namespace NHCodeFirst.FluentMapper
{
    using HbmModel;

    public class ColumnMapper<TChild>
    {
        private readonly Column column;
        protected TChild child;

        internal ColumnMapper(Column column)
        {
            this.column = column;
        }

        public TChild ColumnName(string name)
        {
            column.Name = "name";
            return child;
        }

        public TChild IsMaxLength()
        {
            column.Length = "10000";
            return child;
        }

        public TChild Length(int length)
        {
            column.Length = length.ToString();
            return child;
        }

        public TChild SqlType(string type)
        {
            column.SqlType = type;
            return child;
        }

        public TChild NotNull(bool value = true)
        {
            column.NotNull = value.ToString();
            return child;
        }

        public TChild Index(string name)
        {
            column.Index = name;
            return child;
        }

        public TChild Default(string value)
        {
            column.Default = value;
            return child;
        }

        public TChild Check(string value)
        {
            column.Check = value;
            return child;
        }

        public TChild Unique(bool value, string name = null)
        {
            column.Unique = value.ToString().ToLower();
            column.UniqueKey = name;
            return child;
        }

        public TChild Precision(int value)
        {
            column.Precision = value.ToString();
            return child;
        }

        public TChild Scale(int value)
        {
            column.Scale = value.ToString().ToLower();
            return child;
        }
    }

    public class ColumnMapper : ColumnMapper<ColumnMapper>
    {
        internal ColumnMapper(Column column)
            : base(column)
        {
        }
    }
}